<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv=X-UA-Compatible content="IE=edge,chrome=1">
    <meta content=always name=referrer>
    <link rel="stylesheet" type="text/css" href="__STATIC__/css-wap/swiper.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/css-wap/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="__STATIC__/css-wap/style.css">
    <script src="__STATIC__/js-wap/jquery-1.11.3.min.js"></script>
    <script src="__STATIC__/js-wap/swiper.min.js"></script>
    <script src="__STATIC__/js-wap/common.js"></script>
    <title>拍卖</title>
    <script>
        $(function () {
            $(".header-lottery ul li").click(
                    function () {
                        $(this).addClass("active").siblings().removeClass("active");
                    }
            );
            $(".close").click(
                    function () {
                        $(this).parents(".cur-state").hide();
                    }
            )
        })
    </script>
</head>
<body style="background: #F6F6F6">
<div class="wrap">
    <div class="header-lottery">
        <ul>
            <li><a href="{:url('mobile/auction/detail',['goods_id'=>$goods_id])}">拍卖详情</a></li>
            <li class="active"><a href="{:url('mobile/auction/spot',['id'=>$goods_id])}">拍卖现场</a></li>
        </ul>
        <a href="javascript:back_url();"><img src="__STATIC__/img-wap/back.png" class="back"></a>
        <!--<a href="#"><img src="__STATIC__/img-wap/share.png" class="share"></a>-->
    </div>
    <div class="lottery-scene">

        <div class="current">
            <div class="cur-heading">
                {notempty name="first"}
                <img id="avatar" src="/{$first.Member.avatar}" onerror=this.src='/static/mobile/img/moren2.jpg'>
                <span id="person" id="person_first">{$first.Member.nickname}</span>
                {/notempty}
                <div>当前价：<br><span id="dangqian">{$dijia}元</span></div>
                <input type="hidden" id="end_time" value="{$action['end_time']}">
                <input type="hidden" id="start_time" value="{$action['start_time']}">
                <input type="hidden" id="goods_id" value="{$goods_id}">
                <input type="hidden" id="draw_id" value="{$action['id']}">
                <input type="hidden" id="bond" value="{$bond}">
            </div>
        </div>
        <ul class="list" id="aaa">
            {volist name="record" id="item"}
            <li>
                <div>
                    <img src="/{$item.Member.avatar}" class="pic" onerror=this.src='/static/mobile/img/moren2.jpg'>
                    <div class="det">
                        <span class="name">{$item.Member.nickname}</span>
                        <div><span class="num">{$item.bind}元</span><span class="valid">有效</span></div>
                    </div>
                </div>
            </li>
            {/volist}
        </ul>
    </div>
    <div class="block"></div>
    <div class="footer-lottery">
        <ul border="1">
            {if condition="$action['end_time'] gt time()"}
            <li class="enter" style="width: 27%;"><a href="javascript:offer();">出价:{$data['bidding']}</a></li>
            {else/}
            <li class="enter"><a href="#">已结束</a></li>
            {/if}
            {eq name="bond" value="2"}
            <li class="enter" style="width:45%;margin-left: 20%;color: white;"><a href="javascript:msn();">保证金金额：&yen;{$data.bond}</a></li>
            {/eq}
        </ul>

    </div>

</div>
{include file="public/src" /}
{if condition="$action['end_time'] gt time()"}
<script>
    $(function () {
        // 开始时间
        var start_time = ($('#start_time').val()) * 1000;
        // 当前时间
        var timestamp = Date.parse(new Date());
        // 距离开始五分钟
        var reday_time = start_time + 36000;
        // 距离开始五分钟开始刷新页面
        if (reday_time < timestamp) {
            sh = setInterval('freshTime()', 3000);
        }
        // 查看是否缴纳保证金
//        bond();

    });


    // 保证金判断
    function bond() {
        var bond = $('#bond').val();
        var goods_id = $('#goods_id').val();
        if (bond == 2) {
            layer.open({content: '您未缴纳保证金，请缴纳保证金', skin: 'msg', time: 5});
            window.location.href = "{:url('mobile/bond/index')}?goods_id="+goods_id;
        }
    }


    // 出价列表
    function freshTime() {
        var end_time = $('#end_time').val();
        var timestamp = Date.parse(new Date());
        var goods_id = $('#goods_id').val();
        var draw_id = $('#draw_id').val();

        if (end_time < timestamp) {
            var new_brand = "";
            $.ajax({
                url: "{:url('mobile/auction/selling')}",
                type: 'get',
                dateType: 'json',
                data: {'goods_id': goods_id, 'draw_id': draw_id},
                success: function (data) {
                    if (data.code == 200) {
                        var brands = data.brands;

                        for (var i = 0; i < brands.length; i++) {
                            var empty_img = "this.src='/static/mobile/img/moren2.jpg'";
                            new_brand += '<li><div><img src="/'+brands[i]['member']['avatar']+'" class="pic" onerror='+empty_img+'>'+
                                    '<div class="det"><span class="name">' + brands[i]['member']['nickname'] + '</span>' +
                                    '<div><span class="num">' + brands[i]['bind'] + '元</span><span class="valid">有效</span></div></li>';

                        }


                        var dangqian = returnFloat(data.currents);

                        $('#aaa').children('li').remove();
                        $('#aaa').html(new_brand);
                        var mm = dangqian+"元";
                        $('#dangqian').text(mm);
                        $('#person').text(data.person);
                        var avatar = "/"+data.avatar;
                        $('#avatar').attr('src',avatar);
                    } else if (data.code == 201) {
                        layer.open({content: '拍卖结束', skin: 'msg', time: 2});

                        new_brand += '<li><div><img src="__STATIC__/img-wap/pic27.png" class="pic">' +
                                '<div class="det"><span class="name">' + data.person + '</span>' +
                                '<div><span class="num">' + data.brands + '元</span><span class="valid">最终拍得商品</span></div></li>';

                        $('#aaa').children('li').remove();
                        $('#aaa').html(new_brand);
                        window.location.reload();
                    }else if(data.code == 402) {
                        layer.open({content: '此商品流拍', skin: 'msg', time: 5});
//                        window.location.href = "{:url('mobile/auction/index')}?id="+draw_id;
                    }else if (data.code == 203) {
                        new_brand += '<li><div><img src="__STATIC__/img-wap/pic27.png" class="pic">' +
                                '<div class="det"><span class="name">' + data.person + '</span>' +
                                '<div><span class="num">' + data.brands + '元</span><span class="valid">最终拍得商品</span></div></li>';

                        $('#aaa').children('li').remove();
                        $('#aaa').html(new_brand);
                        window.location.reload();
                    }
                }
            });
        }
    }


    function returnFloat(value){
        var value=Math.round(parseFloat(value)*100)/100;
        var xsd=value.toString().split(".");
        if(xsd.length==1){
            value=value.toString()+".00";
            return value;
        }
        if(xsd.length>1){
            if(xsd[1].length<2){
                value=value.toString()+"0";
            }
            return value;
        }
    }

    function msn() {
        var goods_id = $('#goods_id').val();
        var draw_id = $('#draw_id').val();
        var bond = $('#bond').val();
        if (bond == 2) {
            layer.open({content: '您未缴纳保证金，请缴纳保证金', skin: 'msg', time: 1});
            window.location.href = "{:url('mobile/bond/index')}?goods_id="+goods_id;

        }else {
            layer.open({content: '您已缴纳过保证金', skin: 'msg', time: 4});
        }
    }


    // 出价功能
    function offer() {

        var goods_id = $('#goods_id').val();
        var draw_id = $('#draw_id').val();
        var bond = $('#bond').val();
        if (bond == 2) {
            layer.open({content: '您未缴纳保证金，请缴纳保证金', skin: 'msg', time: 1});
            window.location.href = "{:url('mobile/bond/index')}?goods_id="+goods_id;
            return;
        }

        $.ajax({
            url: "{:url('mobile/auction/chujia')}",
            type: 'post',
            data: {'goods_id': goods_id, 'draw_id': draw_id},
            dateType: 'json',
            success: function (data) {

                if (data.code == 200) {
                    var mm = "起拍价" + data.price;
                    $('#jia').html(mm);
                    layer.open({content: '出价成功', skin: 'msg', time: 4});
                    window.location.reload();
                }else if (data.code == 405){
                        layer.open({content: '拍卖未开始', skin: 'msg', time: 2});
                }else {
                    layer.open({content: '您的价格最高不能出价', skin: 'msg', time: 4});
                }
            }
        })
    }
</script>
{/if}
<script>
    function back_url(){

        var url = sessionStorage.getItem('spot_url_back');
        window.location.href = url;
//        {:url('mobile/auction/index',['id'=>$data['auction_id']])}
//        if (!url){
//            window.location.href = sessionStorage.getItem('spot_url_back');
//        }else{
//            sessionStorage.removeItem('come_order_yes');
//
//        }
    }

</script>
</body>
</html>